package com.yuan.task.controller;

import cn.common.result.Response;


import cn.model.MemberTask;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yuan.security.annotation.RequiresLogin;
import com.yuan.system.api.client.MemberToken;
import com.yuan.system.api.client.TaskClient;
import com.yuan.task.mapper.MemberTaskMapper;
import com.yuan.task.service.MemberTaskService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private MemberTaskService memberTaskService;
//    @Autowired
//    private RemoteUserClient remoteUserClient;
//    @Autowired
//    private ResilienService resilienService;
   // @Autowired
    //private MemberToken memberToken;
    @Autowired
    private TaskClient taskClient;
    @Autowired
    private MemberTaskMapper  memberTaskMapper;
//    @GetMapping("/user")
//    public Response getUser(@RequestParam String phone) {
//        CompletableFuture<List<Member>> member = remoteUserClient.getUserInfo(phone);
//        log.info("用户:{}", member);
//        return Response.Success();
//    }
//
//    @GetMapping("/resilien")
//    public Response resilien(Integer id) {
//        resilienService.doSomething(id);
//
//        return Response.Success();
//    }
    @GetMapping("/list")
    @GlobalTransactional
    public Response getList(){
       // String s = memberToken.info();
       String s = taskClient.list();

       QueryWrapper<MemberTask> memberTaskQueryWrapper = new QueryWrapper<>();
        memberTaskQueryWrapper.eq("member_id","c64b1bb132cde6d2d2a7a473bf913a85");
        MemberTask memberTask =  memberTaskMapper.selectOne(memberTaskQueryWrapper);
        memberTask.setTaskImg("11111111111");
        memberTaskMapper.updateById(memberTask);

        return Response.Success(s);
    }

    @RequiresLogin
    @PostMapping("/addTask")
    public Response addTask(@RequestBody MemberTask memberTask){
        return Response.Success(memberTaskService.saveMemberTask(memberTask));
    }
}
